package com.woniuxy.bases.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.bases.entity.Type;
import com.woniuxy.bases.entity.dto.TypeAddDTO;
import com.woniuxy.bases.entity.dto.TypeGetDTO;
import com.woniuxy.bases.entity.dto.TypeUpdateDTO;
import com.woniuxy.bases.mapper.TypeMapper;
import com.woniuxy.bases.service.TypeService;
import com.woniuxy.comments.util.CustomPage;
import com.woniuxy.comments.util.ResponseResult;
import com.woniuxy.comments.util.ResponseState;
import jdk.nashorn.internal.codegen.TypeMap;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class TypeServiceImpl implements TypeService {
    @Resource
    private TypeMapper typeMapper;
    @Override
    public boolean addType(TypeAddDTO typeAddDTO) {
        return typeMapper.addType(typeAddDTO);
    }

    @Override
    public ResponseResult<CustomPage<List<Type>>> getAllType(TypeGetDTO typeGetDTO) {
        PageHelper.startPage(typeGetDTO.getPage().getPageIndex(),typeGetDTO.getPage().getPageSize());
        List<Type> list=typeMapper.getAllType(typeGetDTO.getTypeStatus());
        PageInfo<Type> pageInfo=new PageInfo<>();
        CustomPage<List<Type>> customPage =new CustomPage<>();
        customPage.setCurrentPage(pageInfo.getPageNum());
        customPage.setTotalPage(pageInfo.getPages());
        customPage.setSize(pageInfo.getSize());
        customPage.setData(list);
        customPage.setTotal(pageInfo.getTotal());
        return new ResponseResult<CustomPage<List<Type>>>()
                .setData(customPage)
                .setCode(200)
                .setMessage("success")
                .setState(ResponseState.SELECT_SUCCESS);
    }

    @Override
    public boolean delType(Integer typeId) {
        return typeMapper.delType(typeId);
    }

    @Override
    public boolean updateType(TypeUpdateDTO typeUpdateDTO) {
        return typeMapper.updateType(typeUpdateDTO);
    }
}
